﻿using System;
using System.Data;
using System.Windows;
using System.Windows.Input;
using Gao.Poker.Services;
using MessageBox = Xceed.Wpf.Toolkit.MessageBox;

namespace Gao.Poker.App
{
    /// <summary>
    /// Interaction logic for LoginWin.xaml
    /// </summary>
    public partial class LoginWin : Window
    {
        public LoginWin()
        {
            InitializeComponent();
#if DEBUG
            tbUser.Text = "admin";
            tbPwd.Password = "admin";
#endif
        }

        private void Login_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(tbUser.Text.Trim()) || String.IsNullOrEmpty(tbPwd.Password))
            {
                MessageBox.Show("用户名密码不能为空", "提示信息");
                return;
            }

            var user = UserService.Instance().Login(tbUser.Text.Trim(), tbPwd.Password);
            if (user != null)
            {
                MainWin win = new MainWin();
                win.User = user;
                win.Show();
                Close();
            }
            else
            {
                MessageBox.Show("用户名或者密码错误", "提示信息");
            }
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("你是否真要退出本系统", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                Close();
                Application.Current.Shutdown(0);
            }
        }

        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }
    }
}
